package com.navinfo.tripanalysis.common.arithmetic;

import com.navinfo.tripanalysis.common.arithmetic.annotation.Arithmetic;
import com.navinfo.tripanalysis.common.arithmetic.common.CommonData;
import com.navinfo.tripanalysis.common.arithmetic.common.OuterStatisticData;
import com.navinfo.tripanalysis.common.arithmetic.common.OuterStatisticExtendedData;
import com.navinfo.tripanalysis.common.arithmetic.custom.VarRangeSpeedUrea;
import com.navinfo.tripanalysis.common.arithmetic.enums.RangeSpeedEnum;
import com.navinfo.tripanalysis.common.arithmetic.manager.AbstractArithmetic;
import com.navinfo.tripanalysis.common.util.ArithmeticUtils;

/**
 * 东风
 * 速度区间尿素消耗统计算法<br/>
 * 输出：统计
 *
 * @author liudong
 */
@Arithmetic(name = "速度区间尿素消耗")
public class RangeSpeedUrea_DF extends AbstractArithmetic<VarRangeSpeedUrea> {

    @Override
    public void calculate() {
        logger.debug("速度区间尿素消耗统计算法.[terminalId:{}]", terminalId);
        VarRangeSpeedUrea var = getObj();
        CommonData commonData = getCommonData();
        int speed = commonData.getSpeedKmh();

        if (speed < 0) {
            logger.error("速度值不合法，不进行统计：speedKmh:{}", speed);
            return;
        }

        int urea = ArithmeticUtils.massToVolume(commonData.getUreaInjection(), commonData.getAtmosphericTem());
        if (urea == 0) {
            return;
        }
        if (RangeSpeedEnum.RANGE_10.getRange().contains(speed)) {
            var.addSpeed10(urea);
        } else if (RangeSpeedEnum.RANGE_20.getRange().contains(speed)) {
            var.addSpeed20(urea);
        } else if (RangeSpeedEnum.RANGE_30.getRange().contains(speed)) {
            var.addSpeed30(urea);
        } else if (RangeSpeedEnum.RANGE_40.getRange().contains(speed)) {
            var.addSpeed40(urea);
        } else if (RangeSpeedEnum.RANGE_50.getRange().contains(speed)) {
            var.addSpeed50(urea);
        } else if (RangeSpeedEnum.RANGE_60.getRange().contains(speed)) {
            var.addSpeed60(urea);
        } else if (RangeSpeedEnum.RANGE_70.getRange().contains(speed)) {
            var.addSpeed70(urea);
        } else if (RangeSpeedEnum.RANGE_80.getRange().contains(speed)) {
            var.addSpeed80(urea);
        } else if (RangeSpeedEnum.RANGE_90.getRange().contains(speed)) {
            var.addSpeed90(urea);
        } else if (RangeSpeedEnum.RANGE_100.getRange().contains(speed)) {
            var.addSpeed100(urea);
        } else if (RangeSpeedEnum.RANGE_110.getRange().contains(speed)) {
            var.addSpeed110(urea);
        } else if (RangeSpeedEnum.RANGE_120.getRange().contains(speed)) {
            var.addSpeed120(urea);
        } else if (RangeSpeedEnum.RANGE_OVER_120.getRange().contains(speed)) {
            var.addSpeedOver120(urea);
        }

        logger.debug("速度区间尿素消耗统计算法结束.[terminalId:{}]", terminalId);
    }

    @Override
    public void collect(OuterStatisticData statisticDataOut) {
        VarRangeSpeedUrea var = getObj();

        OuterStatisticExtendedData extendedData = statisticDataOut.getExtendedData();
        extendedData.setSpeedRange01Urea(var.getSpeed10());
        extendedData.setSpeedRange02Urea(var.getSpeed20());
        extendedData.setSpeedRange03Urea(var.getSpeed30());
        extendedData.setSpeedRange04Urea(var.getSpeed40());
        extendedData.setSpeedRange05Urea(var.getSpeed50());
        extendedData.setSpeedRange06Urea(var.getSpeed60());
        extendedData.setSpeedRange07Urea(var.getSpeed70());
        extendedData.setSpeedRange08Urea(var.getSpeed80());
        extendedData.setSpeedRange09Urea(var.getSpeed90());
        extendedData.setSpeedRange10Urea(var.getSpeed100());
        extendedData.setSpeedRange11Urea(var.getSpeed110());
        extendedData.setSpeedRange12Urea(var.getSpeed120());
        extendedData.setExceedSpeedRangeUrea(var.getSpeedOver120());
    }
}
